//
//  CustomView.m
//  Doctor
//
//  Created by 阳光 on 16/9/26.
//  Copyright © 2016年 阳光. All rights reserved.
//

#import "CustomView.h"

@implementation CustomView

-(instancetype)initWithTitle:(NSString *)title imageUrl:(NSString *)imageUrl
{
    if (self=[super init])
    {
        self.titleStr=title;
        self.titleLabel.textColor=Color000000;
        self.backgroundColor=WhiteColor;
        self.imageUrl.image=[UIImage imageNamed:imageUrl];
    }
    return self;
}

// 预防
- (instancetype)init {
    if (self = [super init]) {
        NSAssert1(NO, @"%s  必须使用initWithTitle:方法初始化", __FUNCTION__);
    }
    return self;
}

-(UILabel *)titleLabel
{
    if (!_titleLabel) {
        _titleLabel=[UILabel new];
        [self addSubview:_titleLabel];
        [_titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.mas_equalTo(self.imageUrl.mas_right).offset(kmargin);
            make.centerY.mas_equalTo(self.imageUrl.mas_centerY);
        }];
        _titleLabel.font=Font_Number(14);
        _titleLabel.text=_titleStr;
    }
    return _titleLabel;
}


-(UIImageView *)imageUrl
{
    if (!_imageUrl) {
        _imageUrl=[UIImageView new];
        [self addSubview:_imageUrl];
        [_imageUrl mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.mas_equalTo(kmargin);
            make.centerY.mas_equalTo(self.mas_centerY);
            make.size.mas_equalTo(CGSizeMake(20,20));
        }];
    }
    return _imageUrl;
}


@end
